import React, { Component, Fragment } from 'react';
import { Card } from 'antd';
import { connect } from 'dva';
import router from 'umi/router';
import styles from './Index.less';

@connect(({ xcxauth, loading }) => ({
  xcxauth,
  authStoreInfo: xcxauth.authStoreInfo,
  loading: loading.effects['xcxauth/GetPreAuthUrl'],
}))
class Auth extends Component {
  state = {
    resultType: 0,
  };
  componentWillMount() {
    const { dispatch, match } = this.props;
    const type = Number(match.params.type);
    if (type) {
      this.setState({
        resultType: type,
      });

      if (type === 51000) {
        dispatch({
          type: 'xcxauth/GetAuthException',
        });
      }
    }
  }
  render() {
    const { cdnUrl, errorInfo } = this.props;
    const { resultType } = this.state;
    return (
      <div>
        <Card>
          <div className={styles.errorBlock}>
            <div style={{marginBottom:'24px'}}><img src={cdnUrl + '/' + 'xkdnewyun/systemfile/store/icon/weapp_fail.png'}/></div>
            <div className={styles.errorText}>授权失败</div>
            {resultType===51000?<div className={styles.errorInfo}>{errorInfo&&errorInfo.AuthCodeMsg}</div>:
            <div className={styles.errorInfo}>服务器异常，请稍后再试</div>}
            {resultType===51000&&errorInfo&&errorInfo.WechartResult?<div className={styles.errorWX}>错误信息：{errorInfo.WechartResult.ErrorCodeValue}。</div>:null}
          </div>
        </Card>
      </div>
    );
  }
}

export default connect(({ global,xcxauth }) => ({
  cdnUrl:global.oemInfo.cdnUrl,
  errorInfo:xcxauth.errorInfo
}))(Auth);
